package com.caosy.grassthinkremote.controller;

import com.caosy.grassthinkremote.common.RespData;
import com.caosy.grassthinkremote.entity.vo.DeliverReq;
import com.caosy.grassthinkremote.service.DeliverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/deliver")
@ResponseBody
public class DeliverController {
    @Autowired
    private DeliverService deliverService;

    @PostMapping("/add")
    public RespData add(@RequestBody DeliverReq req, HttpServletRequest request) {
        RespData resp = null;
        try{
            resp = deliverService.add(req,request);
        } catch (Exception e) {
            return RespData.getFailure(e.getMessage());
        }
        return resp;
    }

    @GetMapping("/list")
    public RespData list(@RequestBody DeliverReq req, HttpServletRequest request) {
        RespData resp = null;
        try{
            resp = deliverService.list(req,request);
        } catch (Exception e) {
            return RespData.getFailure(e.getMessage());
        }
        return resp;
    }

    @PostMapping("/push")
    public RespData push(@RequestBody DeliverReq req) {
        RespData resp = null;
        try{
            resp = deliverService.push(req);
        } catch (Exception e) {
            return RespData.getFailure(e.getMessage());
        }
        return resp;
    }

    @PostMapping("/pass")
    public RespData pass(@RequestBody DeliverReq req) {
        RespData resp = null;
        try{
            resp = deliverService.pass(req);
        } catch (Exception e) {
            return RespData.getFailure(e.getMessage());
        }
        return resp;
    }
}
